#!/bin/bash
# Script to create a Bitsand release

# Do not include trailing /
SOURCE_DIR=/home/russ/russ/bitsand
WORK_DIR=/home/russ

clear
echo "Select which system this release is for:"
select LM in LT Maelstrom;
do
	echo "Creating $LM release"
	break;
done

read -p "Enter version: " VERSION
RELEASE_DIR=$WORK_DIR"/Bitsand_"$LM"_"$VERSION
mkdir $RELEASE_DIR
cp -r $SOURCE_DIR"/bitsand" $RELEASE_DIR
rm -rf $RELEASE_DIR"/bitsand/NON_WEB"

# Copy documentation
cp $SOURCE_DIR"/wiki/AdminManual.wiki" $RELEASE_DIR"/Admin_Manual.txt"
cp $SOURCE_DIR"/wiki/AdminInstall.wiki" $RELEASE_DIR"/INSTALL.txt"
cp $SOURCE_DIR"/bitsand/NON_WEB/ChangeLog.txt" $RELEASE_DIR"/CHANGE_LOG.txt"
cp $SOURCE_DIR"/bitsand/NON_WEB/BlankSign-inSheet.pdf" $RELEASE_DIR"/BlankSign-inSheet.pdf"

# Remove .svn folders
rm -rf $RELEASE_DIR"/bitsand/.svn/"
rm -rf $RELEASE_DIR"/bitsand/admin/.svn/"
rm -rf $RELEASE_DIR"/bitsand/img/.svn/"
rm -rf $RELEASE_DIR"/bitsand/inc/.svn/"
rm -rf $RELEASE_DIR"/bitsand/install/.svn/"

# System-specific code
if [ $LM = "LT" ]
then
	# LT
	cp $SOURCE_DIR"/bitsand/NON_WEB/README.txt" $RELEASE_DIR"/README.txt"
	# Delete Maelstrom files
	rm $RELEASE_DIR"/bitsand/ic_form_m.php"
	rm $RELEASE_DIR"/bitsand/ic_view_m.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_bookings_csv_m.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_edit_ic_m.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_viewdetails_m.php"
	# Set RPG_NAME to 'LT'
	sed s/"\/\/define (RPG_NAME, 'LT');"/"define (RPG_NAME, 'LT');"/ $SOURCE_DIR"/bitsand/inc/inc_config_dist.php" > $RELEASE_DIR"/bitsand/inc/inc_config_dist.php"
else
	# Maelstrom
	cp $SOURCE_DIR"/bitsand/NON_WEB/README_m.txt" $RELEASE_DIR"/README.txt"
	# Delete LT files
	rm $RELEASE_DIR"/bitsand/ic_form.php"
	rm $RELEASE_DIR"/bitsand/ic_view.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_bookings_csv.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_edit_ic.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_groups.php"
	rm $RELEASE_DIR"/bitsand/admin/admin_viewdetails.php"
	# Rename Maelstrom files
	mv $RELEASE_DIR"/bitsand/ic_form_m.php" $RELEASE_DIR"/bitsand/ic_form.php"
	mv $RELEASE_DIR"/bitsand/ic_view_m.php" $RELEASE_DIR"/bitsand/ic_view.php"
	mv $RELEASE_DIR"/bitsand/admin/admin_bookings_csv_m.php" $RELEASE_DIR"/bitsand/admin/admin_bookings_csv.php"
	mv $RELEASE_DIR"/bitsand/admin/admin_edit_ic_m.php" $RELEASE_DIR"/bitsand/admin/admin_edit_ic.php"
	mv $RELEASE_DIR"/bitsand/admin/admin_viewdetails_m.php" $RELEASE_DIR"/bitsand/admin/admin_viewdetails.php"
	# Set RPG_NAME to 'Maelstrom'
	sed s/"\/\/define (RPG_NAME, 'Maelstrom');"/"define (RPG_NAME, 'Maelstrom');"/ $SOURCE_DIR"/bitsand/inc/inc_config_dist.php" > $RELEASE_DIR"/bitsand/inc/inc_config_dist.php"
fi

echo "Finished. Now create PDFs of the AdminInstall, AdminManual & AdminRoot wiki pages and put them in the release directory, then create a zip"
